import { BasicForm } from '@/components/ProForm/interface/index';
import { PublicInterface } from '@/interface/public';

import { defaultStyle } from '@/basic/style';
export function useAddDetailForm(proTableBox: PublicInterface.ProTableValue) {
  let addDetailForm = reactive<BasicForm>({
    form: {},
    title: '',
    visible: false,
    transitionArr: [
      {
        oldField: 'gender',
        newField: 'gender'
      }
    ],
    options: [
      {
        label: 'id',
        prop: 'id',
        hide: true,
        type: 'input',
        defaultValue: ''
      },
      {
        type: 'input',
        label: 'taskId',
        hide: true,
        prop: 'taskId',
        defaultValue: ''
      },
      {
        type: 'input',
        label: '耗时',
        defaultValue: '',
        hide: false,
        prop: 'h',
        attrs: {
          type: 'number',
          placeholder: '耗时(小时)'
        },
        rules: [{ required: true, message: '', trigger: 'change' }]
      },
      {
        type: 'input',
        label: '汇报内容',
        defaultValue: '',
        hide: false,
        prop: 'reportText',
        attrs: {
          style: defaultStyle,
          type: 'textarea'
        },
        rules: [{ required: true, message: '', trigger: 'change' }]
      },
      {
        type: 'input',
        label: 'remark',
        defaultValue: '',
        hide: false,
        prop: 'remark',
        attrs: {
          style: defaultStyle
        }
      }
    ],
    // 提交表单
    commitForm: async form => {
      const params = { ...form };
      params.minute = params.h * 60;
      !form.id ? await taskDetailSave(form) : await taskDetailUpdate(form);
      addDetailForm.visible = false;
      elMessage();
      // proTableBox.value.element.updateKeyChildren(form.targetPid, data);
      proTableBox.value?.getTableList();
    }
  });

  return { addDetailForm };
}
